<?php
/* 
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

class Application_Model_DbTable_Testimony extends Zend_Db_Table_Abstract{

    protected $_name = 'Testimony';

    public function addTestimony($transactionId,$shopId,$buyerId){
        $data = array(
            "transaction_id" => $transactionId,
            "shop_id" => $shopId,
            "buyer_id" => $buyerId

        );
        $this->insert($data);
    }

    public function insertTestimony($testimony_id,$testimony){
        $data = array(
            "testimony" => $testimony
        );
        //$this->insert($data);
        $this->update($data, "testimony_id = ".(int)$testimony_id);
    }

    public function getTestimonyByShop($shopId){
        $query = $this->select();
        $query->from(array('t'=>'Testimony'));
        $query->joinInner(array('b'=>'Buyer'),'b.buyer_id = t.buyer_id',array('b_username'=>'b.username'));
        $query->setIntegrityCheck(false);
        $query->where("shop_id = $shopId AND (NOT testimony IS null OR testimony = '')");
        return $this->fetchAll($query);
    }

    public function getShopId($testimony_id){
        $row = $this->fetchRow("testimony_id = ".$testimony_id." ");
        if(!$row) return -1;
        else return $row->shop_id;
    }

    public function getBuyerId($testimony_id){
        $row = $this->fetchRow("testimony_id = ".$testimony_id." ");
        if(!$row) return -1;
        else return $row->buyer_id;
    }

    public function getTestimonybyBuyer($buyer_id){

        $query = $this->select();
        $query->from(array('t'=>'Testimony'));
        $query->joinInner(array('s'=>'Shop'),'s.shop_id = t.shop_id',array('s_name'=>'name'));
        $query->setIntegrityCheck(false);
        $query->where("t.testimony is null AND buyer_id = $buyer_id");
        return $this->fetchAll($query);
    }

}

?>
